/**
 * Author: ligj@mapbar.com
 * Create Time: 2018/01/05 15:10
 * Description:
 */
import actions from '../actions';
import { MODAL_PUSH_PAGE, MODAL_REMOVE_PAGE, MODAL_UPDATE_PAGE,SET_ROLES} from '../mutations';
const moduleModalPages = {
    state: {
        pages: [],
	    roles:{}
    },
    mutations: {
        [MODAL_PUSH_PAGE] (state, pageConfig) {
            if (state.pages.findIndex(item => item.state.name === pageConfig.state.name) === -1) {
                state.pages.push(pageConfig);
            }
        },
        [MODAL_REMOVE_PAGE] (state, pageConfig){
            let idx = state.pages.findIndex(item => item.state.name === pageConfig.state.name);
            if (idx > -1) {
                state.pages.splice(idx, 1);
            }
        },
        [MODAL_UPDATE_PAGE] (state, pageConfig){
            let idx = state.pages.findIndex(item => item.state.name === pageConfig.state.name);
            if (idx > -1) {
                state.pages[idx] = pageConfig;
            }
        },
	    [SET_ROLES](state,roles){
        	state.roles = roles;
	    }
    },
    actions: {
	    ...actions
    },
    getters: {}
};

export default moduleModalPages;
